/**
 *
 */
Ext.define('Admin.view.waterOptimum.resultshow.reserviorSingle',{
	extend:'Ext.panel.Panel',
	xtype:'woReserviorSingle',
	//起别名
	alias:'woReserviorSingle',
	require:[],
	user:[],
	userCLs:'big-100 small-100',
	layout: {
        type: 'hbox',
        align: 'stretch'
    },
    dataPack: null,
	items:[{
		xtype: 'panel',
		flex: 1,
		layout: {
	        type: 'vbox',
	        align: 'stretch'
	    },
		items: [{
			xtype: 'wohighchart',
			border: false,
			flex:1
		},{
			xtype: 'wohighchart',
			border: false,
			flex:1
		}]
	},{
		xtype: 'grid',
		border: true,
	    margin: '0 10 10 30',
	    store: {xtype: 'store'},
	    columns: [
	    	{ text: '时间', dataIndex: 'index1', width: '15%', minWidth: 100, align: 'center'},
	        { text: '入库', dataIndex: 'index2', width: '16%', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
	        { text: '水位', dataIndex: 'index4', width: '16%', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
	        { text: '出流', dataIndex: 'index3', width: '16%', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
	        { text: '水位上限', dataIndex: 'index5', width: '17%', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
	        { text: '水位下限', dataIndex: 'index6', width: '17%', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
	    ],
	    flex: 1
	}],
	currentPage: null,
	getStore: function(){
		return this.query('grid')[0].getStore();
	},
	displayData: function(data){
		this.currentPage = null;
		this.dataPack = data;
		this.changeView(1);
	},
	getChart:function(i){
		return this.query('wohighchart')[i];
	},
	changeView: function(id){
		var dataSource = this.dataPack;
		if(this.currentPage != id){
			this.currentPage = id;
			if(dataSource != null){
				var data = eval("dataSource.index"+(id+1))
				this.getStore().setData(data);
				var opt1 = this.getChartOption1();
				opt1.title.text = "流量过程图";
				opt1.xAxis.categories = this.getDataArray(this.getStore(), 'index1');
				opt1.series[0].data = this.getDataArray(this.getStore(), 'index2');
				opt1.series[1].data = this.getDataArray(this.getStore(), 'index3');
				this.getChart(0).chartDraw(opt1);
				var opt2 = this.getChartOption2();				
				opt2.title.text = "水位变化";
				opt2.xAxis.categories = this.getDataArray(this.getStore(), 'index1');
				opt2.series[0].data = this.getDataArray(this.getStore(), 'index4');
				this.getChart(1).chartDraw(opt2);
			}			
		}
	},
	getDataArray: function(store, index) {
		var output = new Array();
		var t = 0;
		for (var i = 0; i < store.getCount(); i++) {
			output[t] = store.getAt(i).get(index);
			t++;
		}
		return output;
	},
	getChartOption1:function(){
		return {
		    title: {
		        text: ''
		    },
		    xAxis: {
		        categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
		    },
		    yAxis: [{
		        title: {
		            text: '流量m³/s'
		        }
		    }/*,{
		    	title: {
		            text: '水位m'
		        },
		        opposite: true
		    }*/],
		    tooltip: {
	            shared: true,
	            crosshairs: true,
	            valueDecimals: 3
	        },
		    series: [{
		        name: '入库',
		        data: []
		    }, {
		        name: '出库',
		        data: []
		    }/*, {
		        name: '水位',
		        yAxis: 1,
		        data: getDataArray(store4r_s1, 'index4', 0, 12)
		    }
		    , {
		        name: '水位上限',
		        yAxis: 1,
		        data: getDataArray(store4r_s1, 'index5', 0, 12)
		    }, {
		        name: '水位下限',
		        yAxis: 1,
		        data: getDataArray(store4r_s1, 'index6', 0, 12)
		    }*/]

		};
	},
	getChartOption2: function(){
		return {
		    title: {
		        text: ''
		    },
		    xAxis: {
		        categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
		    },
		    yAxis: {
		        title: {
		            text: '水位m'
		        }
		    },
		    legend: {
		    	enabled: false
		    },
		    series: [{
		    	type: 'column',
		    	name: '水位',
		        data: []
		    }]
		};
	}
});
